<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class VipBaseInfo extends Model
{
    const DATE_TYPE_DAY = 1;
    const DATE_TYPE_MONEY = 2;
    const DATE_TYPE_QUARTER = 3;
    const DATE_TYPE_YEAR = 4;

    const IS_EXEMPT_ADS = 1;
    const NOT_EXEMPT_ADS = 2;


    protected $fillable = [
        'name',
        'price',
        'free_homework_help_count',
        'homework_help_discount',
        'algorithm_sources_icon',
        'free_algorithm_sources_count',
        'algorithm_sources_discount',
        'resource_point',
        'free_resource_point_count',
        'resource_discount',
        'is_exempt_ads',
        'privilege_str',
        'date_type',
        'date_length',
    ];

    public $timestamps = true;

    /**
     * @param Carbon $startData
     * @return string
     */
    public function getExpireDate(Carbon $startData)
    {
        if ($this->attributes['date_type'] == VipBaseInfo::DATE_TYPE_DAY) {
            $expireDate = $startData->addDays($this->attributes['date_length']);
        } else if ($this->attributes['date_type'] == VipBaseInfo::DATE_TYPE_MONEY) {
            $expireDate = $startData->addMonths($this->attributes['date_length']);
        } else if ($this->attributes['date_type'] == VipBaseInfo::DATE_TYPE_QUARTER) {
            $expireDate = $startData->addQuarters($this->attributes['date_length']);
        } else {
            $expireDate = $startData->addYears($this->attributes['date_length']);
        }

        return $expireDate->toDateTimeString();
    }
}
